package com.service.impl;

import com.dao.PraiseDao;
import com.entity.Praise;
import com.service.PraiseService;
import com.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * date:2021/4/29
 * description:
 * Author:Stargazer
 */
@Service
public class PraiseServiceImpl implements PraiseService {
    @Autowired
    private PraiseDao praiseDao;


    @Override
    public AjaxResult doPraise(Integer uId, Integer commentId) {
        Praise praise = praiseDao.selectPraiseByUidAndCommentId(uId, commentId);
        System.out.println("prise="+praise);
        AjaxResult ajaxResult = null;
        if (praise==null){  //查询数据库没有该对象，则增加点赞，返回ture
            int i = praiseDao.insertPraise(uId, commentId, new Date());
            if (i==1){
                return new AjaxResult(true,"点赞成功",true);
            }
        }//如果有对象,则删除点赞记录
        praiseDao.deletePraise(uId, commentId);
        return new AjaxResult(false,"取消点赞成功",false);
    }
}
